package com.lbn.monitor.app.warning.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.lbn.monitor.R;
import com.lbn.monitor.api.model.AlarmDevice;
import com.lbn.monitor.widget.calendar.TimeUtils;

import java.text.DecimalFormat;
import java.util.List;

import butterknife.BindView;
import indi.free.widgets.custom_recycler_view.BasePagerRecyclerAdapter;
import indi.free.widgets.custom_recycler_view.RecyclerViewHolder;

/**
 * @author 李炳南
 * @date 2017/3/6
 */
public class WarningAdapter extends BasePagerRecyclerAdapter<AlarmDevice> {


    public WarningAdapter(Context ctx, RecyclerView recyclerView, List<AlarmDevice> list) {
        super(ctx, recyclerView, list);
    }

    @Override
    public int getItemLayoutId() {
        return R.layout.layout_item_warning;
    }

    @Override
    public void bindData(RecyclerViewHolder holder, int position, AlarmDevice item) {
        double UpLimit = Double.valueOf(item.getUpLimit());
        double DownLimit = Double.valueOf(item.getDownLimit());
        double standardvalue = Double.valueOf(item.getStandardvalue());
        double realTimeValue = Double.valueOf(item.getRealTimeValue());
        String type = null;
        double scale = 0;
        if(UpLimit < realTimeValue){
            type = "超过上限";
            scale = realTimeValue/standardvalue;
        }
        else if(DownLimit>realTimeValue){
            type = "超过下限";
            scale = standardvalue/realTimeValue;
        }

        holder.getTextView(R.id.name).setText("设备名称 : "+item.getTreename());
        holder.getTextView(R.id.mn).setText("设备MN号 : "+item.getDeviceMN());
        holder.getTextView(R.id.time).setText(item.getDataTime());
        holder.getTextView(R.id.type).setText(type==null?item.getAlarmType():type);
        holder.getTextView(R.id.pollutants).setText(item.getPollutantsFactor());
        holder.getTextView(R.id.monitor).setText(item.getRealTimeValue());
        holder.getTextView(R.id.standard).setText(item.getStandardvalue());
        holder.getTextView(R.id.scale).setText(new DecimalFormat("0.00").format(scale));
    }

}
